/**
 * Created by dell on 2018/12/6.
 */

/*
get参数处理
 */
const url = require('url');

// let str  = 'http://www.baidu.com/abc?flag=123&keyword=java';
// let ret = url.parse(str);
// //第二个参数写true就会把jQuery的内容变成对象，之前是字符串

//url.parse()将字符串转换成对象

// // let ret = url.parse(str,true);
// console.log(ret);
// // console.log(ret.query);

/*结果为：
 Url {
 protocol: 'http:',
 slashes: true,
 auth: null,
 host: 'www.baidu.com',
 port: null,
 hostname: 'www.baidu.com',
 hash: null,
 search: '?flag=123&keyword=java',
 query: { flag: '123', keyword: 'java' },
 pathname: '/abc',
 path: '/abc?flag=123&keyword=java',
 href: 'http://www.baidu.com/abc?flag=123&keyword=java' }
 */


let obj = {
    protocol: 'http:',
    slashes: true,
    auth: null,
    host: 'www.baidu.com',
    port: null,
    hostname: 'www.baidu.com',
    hash: null,
    search: '?flag=123&keyword=java',
    query: { flag: '123', keyword: 'java' },
    pathname: '/abc',
    path: '/abc?flag=123&keyword=java',
    href: 'http://www.baidu.com/abc?flag=123&keyword=java'
};
//url.format()将对象转换成字符串
let ret1=url.format(obj);
console.log(ret1);

/*
 结果为：
 http://www.baidu.com/abc?flag=123&keyword=java
 */